package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-09-11
 * Time: 16:21
 */

@RestController
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/set_val")
    public void setVal(@RequestParam("key") String key, @RequestParam("value") String value) {
        redisTemplate.opsForValue()
                .set(key, value);
        //set的重载方法是可以设置其他属性的
    }

    @RequestMapping("/get_val")
    public String getVal(@RequestParam("key") String key) {
        return (String) redisTemplate.opsForValue()
                .get(key);
        //get的重载方法是可以设置其他属性的
    }

}
